[MOD-13325] Add query preprocessing to QuantPreprocessor for asymmetric distance computation
#876
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
In asymmetric scalar quantization, the storage vectors are quantized to
uint8_twhile query vectors remain as floats. The distance formulas require precomputed sums from the query vector:IP(x, y) = min * Σy_i + delta * Σ(q_i * y_i)— requiresy_sum = Σy_i||x - y||² = x_sum_squares - 2 * IP(x, y) + y_sum_squares— requiresy_sum_squares = Σy_i²Previously, these values would need to be computed during each distance calculation. By precomputing them during query preprocessing, we move this cost to a one-time operation per query.
New Functionality
QuantPreprocessor::preprocessQuerynow:(dim + 1) * sizeof(DataType)y_sum = Σy_iy_sum_squares = Σy_i²Query blob layout:
Usage in Distance Calculator
The asymmetric distance function can now retrieve the precomputed value directly from the query blob at offset
dim, avoiding redundant summation during each distance computation.